<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>echarts</title>
    <style>
      .container {
        width: 800px;
        height: 400px;
      }
    </style>
  </head>
  <body>
    <div class="container"></div>
    <script src="./echarts.js"></script>
    <script>
      const myEcharts = echarts.init(document.querySelector(".container"));

      function random(len) {
        const arr = [];
        for (let index = 0; index < len; index++) {
          arr.push(Math.round(Math.random() * 100));
        }
        return arr;
      }

      const option = {
        // 标题
        title: {
          text: "图表~~~",
          left: "center",
        },
        // x轴
        xAxis: {
          data: [
            "一月",
            "二月",
            "三月",
            "四月",
            "五月",
            "六月",
            "七月",
            "八月",
            "九月",
            "十月",
            "十一月",
            "十二月",
          ],
        },
        // y轴
        yAxis: {
          axisLine: {
            show: true,
          },
          axisTick: {
            show: true,
          },
        },
        // 提示框
        tooltip: {},
        // 图例：切换显示组件
        legend: {
          data: ["bar", "line", "pie"],
          top: 30,
        },
        // 工具箱
        toolbox: {
          feature: {
            saveAsImage: {},
            restore: {},
            dataView: {},
          },
        },
        dataZoom: {
          type: "slider",
        },
        series: [
          {
            name: "bar",
            type: "bar",
            data: random(12),
          },
          {
            name: "line",
            type: "line",
            data: random(12),
          },
          {
            name: "pie",
            type: "pie",
            data: [
              {
                name: "xx",
                value: 11,
              },
              {
                name: "yy",
                value: 22,
              },
              {
                name: "zz",
                value: 33,
              },
            ],
            radius: [0, 50],
            center: [600, 60],
          },
        ],
      };

      myEcharts.setOption(option);
    </script>
  </body>
</html>
